package com.attack.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attack.manager.OrderDetailManager;
import com.attack.manager.ReportManager;
import com.common.utils.ExportUtil;
import com.framework.web.BaseController;

@Controller
@RequestMapping(value = "/management/report")
public class ReportController extends BaseController{
	 
    @Autowired
	private ReportManager reportManager;
    
    @Autowired
	private OrderDetailManager orderDetailManager;
    
   
	@ResponseBody
	@RequestMapping("/statOrgOrder")
	public Object statOrgOrder(HttpServletResponse response,HttpServletRequest request) {
		try{
			String message =reportManager.statOrgOrder();
			return jsonReturn(response, 200, message);
		} catch (Exception e) {
			e.printStackTrace();
			return super.jsonReturn(response,300,e.getMessage(),false);
		}
	}
	
	/**
	 * 导出日付息明细报表
	 * @param request
	 * @param response
	 */
	@RequestMapping("/exportDayIncome")
	public void exportDayIncome(HttpServletRequest request,HttpServletResponse response){
		
		String startIncomeDate = request.getParameter("startIncomeDate");
		String endIncomeDate = request.getParameter("endIncomeDate");
		Map paraMap = new HashMap();
		paraMap.put("startIncomeDate",startIncomeDate);
		paraMap.put("endIncomeDate", endIncomeDate);
		List dataList = orderDetailManager.getObjectList("exportDayIncomeList",paraMap);
		
		String[] headers = new String[5];
		headers[0] = "客户姓名";
		headers[1] = "合同号";
		headers[2] = "银行账号";
		headers[3] = "还款日期";
		headers[4] = "还款金额";
		
		String[] keys = new String[5];
		keys[0] = "custName";
		keys[1] = "contractNum";
		keys[2] = "bankAccount";
		keys[3] = "orderMonth";
		keys[4] = "monthIncome";
		
		ExportUtil.exportCsv(response, headers, keys, dataList, "exportDayIncome");
		
	}
	
	
}